<html>
<head><meta charset="utf-8"><title>forbid item definitions inside function bodies · edition 2021 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/index.html">edition 2021</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html">forbid item definitions inside function bodies</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221254841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221254841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221254841">(Dec 30 2020 at 23:16)</a>:</h4>
<p>Nesting items inside functions isn't supported by rust-analyzer. It hurts incrementality for end-to-end queries as it requires invalidating name resolution every time a function body changes. And it can be strange. For example you are allowed to nest <code>mod foo;</code> or <code>mod foo {}</code> inside a function. Forbidding items inside functions could possibly also help with parser recovery when you forget a closing <code>}</code> as rustc can insert as many <code>}</code> as necessary when it hits a keyword that starts an item when it is inside a function.</p>



<a name="221254976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221254976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221254976">(Dec 30 2020 at 23:19)</a>:</h4>
<p>I think last time the team talked about it the consensus was that "no items in function bodies" was too strict to be accepted, so it would need a more nuanced proposal.</p>
<p>As a possible starting point, perhaps something like "no <code>impl</code>s inside a function for types declared outside that function".</p>



<a name="221255065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255065">(Dec 30 2020 at 23:20)</a>:</h4>
<p>FWIW <a href="http://docs.rs">docs.rs</a> does actually use this in real code <a href="https://github.com/rust-lang/docs.rs/blob/f029d0ba7566358afa82245aeb9fec0375609257/src/web/releases.rs#L226">https://github.com/rust-lang/docs.rs/blob/f029d0ba7566358afa82245aeb9fec0375609257/src/web/releases.rs#L226</a></p>



<a name="221255123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255123">(Dec 30 2020 at 23:21)</a>:</h4>
<p><code>rustc</code> uses them too</p>



<a name="221255172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255172">(Dec 30 2020 at 23:22)</a>:</h4>
<p>Yeah, lots of code uses local types.  Here's a <code>core</code> example: <a href="https://doc.rust-lang.org/1.48.0/src/core/ptr/mod.rs.html#455-514">https://doc.rust-lang.org/1.48.0/src/core/ptr/mod.rs.html#455-514</a></p>



<a name="221255184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255184">(Dec 30 2020 at 23:22)</a>:</h4>
<p>Ah, maybe not <code>impl</code>s inside a function for types declared outside that function</p>



<a name="221255383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255383">(Dec 30 2020 at 23:26)</a>:</h4>
<p><span class="user-mention silent" data-user-id="255061">Léo Lanteri Thauvin</span> <a href="#narrow/stream/268952-edition/topic/forbid.20item.20definitions.20inside.20function.20bodies/near/221255184">said</a>:</p>
<blockquote>
<p>Ah, maybe not <code>impl</code>s inside a function for types declared outside that function</p>
</blockquote>
<p>Exactly, yeah.  A local type that derives <code>Copy+Clone</code>, for example, is quite reasonable, hence allowing impls inside a function for a type inside that function.  And because the type is local, that shouldn't require invalidating all of name resolution for every function body change -- just for the changed function body.</p>
<p>But I know no reason to put an impl for an external type inside a function, so restricting that seems quite reasonable.</p>



<a name="221255444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255444">(Dec 30 2020 at 23:27)</a>:</h4>
<p>What does <code>mod foo;</code> in a function even do?</p>



<a name="221255453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255453">(Dec 30 2020 at 23:28)</a>:</h4>
<p>I would <em>expect</em> it to be the same as <code>mod foo;</code> outside the function</p>



<a name="221255489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255489">(Dec 30 2020 at 23:28)</a>:</h4>
<p>I personally think that the more scoped a definition is, the better. While I can imagine that from the compiler's point of view, it can be a very annoying thing to support, it is a great capability of the language, one that coupled to <code>const _: () = { ... };</code>, has allowed to avoid having macros forge unique identifiers for <em>ad-hoc</em> modules or <em>ad-hoc</em> helper types.<br>
Personally, if this capability were to be removed with the only way to opt into it being to remain in an old edition, I would choose to choose to stick to that older edition, for instance.</p>



<a name="221255507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255507">(Dec 30 2020 at 23:28)</a>:</h4>
<p>(I am talking about the initial suggestion, I'll have to think about impls for non-involved types)</p>



<a name="221255541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255541">(Dec 30 2020 at 23:29)</a>:</h4>
<p>Macros generally provide a good source of use cases of items in weird places</p>



<a name="221255586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221255586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221255586">(Dec 30 2020 at 23:30)</a>:</h4>
<p>Note that something that I find great to do is, since construction and destruction are deeply tied, to <code>impl Drop</code> for a type within the body of its constructor. This is especially useful for <code>unsafe</code> code, where there may be less type safety to protect against incorrect refactorings, and so minimal distance between allocation and deallocation, for instance, is quite nice.</p>



<a name="221256011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221256011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221256011">(Dec 30 2020 at 23:37)</a>:</h4>
<p>But yes, I think that [forbidding]  <code>impl</code>s for <em>completely unrelated</em> types ought to be fine.<br>
One thing about these items inside blocks thing, however, is that items defined there cannot be referred to by "explicit paths".<br>
That is,</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="w">    </span><span class="k">mod</span> <span class="nn">bar</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">foo</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="c1">//error</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">foo</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span>::<span class="n">foo</span><span class="p">;</span><span class="w"> </span><span class="c1">// error</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I'd love for these relative namespacing rules to become more consistent, but so doing would be breaking and require, I think, more than an edition change, plus it may require changes in the compiler in order to better represent these unnamed namespaces (I don't know)</p>



<a name="221256621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221256621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221256621">(Dec 30 2020 at 23:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232018">Daniel Henry-Mantilla</span> <a href="#narrow/stream/268952-edition/topic/forbid.20item.20definitions.20inside.20function.20bodies/near/221255489">said</a>:</p>
<blockquote>
<p>I personally think that the more scoped a definition is, the better.</p>
</blockquote>
<p>For things that need to <em>be referenced by their name to use them</em>, I agree, because "more scoped" is implicitly restricted by "but not so much that they can't be used by the places that need them".</p>
<p>But <code>impl</code>s just magically work from everywhere, so there <em>isn't</em> as "most scoped" location right now.  So I think a restriction like "but not any more scoped that the most-scoped or the type or the trait" (precise details TBD) would make sense.</p>



<a name="221256711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221256711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221256711">(Dec 30 2020 at 23:50)</a>:</h4>
<p>Or to say it indirectly, it's weird that rustdoc needs to look inside function bodies.</p>



<a name="221256980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221256980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221256980">(Dec 30 2020 at 23:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/268952-edition/topic/forbid.20item.20definitions.20inside.20function.20bodies/near/221256711">said</a>:</p>
<blockquote>
<p>Or to say it indirectly, it's weird that rustdoc needs to look inside function bodies.</p>
</blockquote>
<p>well, <code>-&gt; impl Trait</code> also messes this up</p>



<a name="221257006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221257006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221257006">(Dec 30 2020 at 23:56)</a>:</h4>
<p>but yeah if items in bodies weren't a thing everybody_loops probably would have trundled along for another few years at least</p>



<a name="221273628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221273628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221273628">(Dec 31 2020 at 06:49)</a>:</h4>
<blockquote>
<p>I personally think that the more scoped a definition is, the better. While I can imagine that from the compiler's point of view, it can be a very annoying thing to support, it is a great capability of the language, one that coupled to <code>const _: () = { ... };</code>, has allowed to avoid having macros forge unique identifiers for <em>ad-hoc</em> modules or <em>ad-hoc</em> helper types.</p>
</blockquote>
<p>Maybe it could only be forbidden for function bodies? Those are the most likely to change.</p>



<a name="221273671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221273671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221273671">(Dec 31 2020 at 06:50)</a>:</h4>
<blockquote>
<p>So I think a restriction like "but not any more scoped that the most-scoped or the type or the trait" (precise details TBD) would make sense.</p>
</blockquote>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="221278550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221278550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> panstromek <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221278550">(Dec 31 2020 at 09:10)</a>:</h4>
<p>Function local trait impls allows you to use local types in their implementations:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Magic</span><span class="p">;</span><span class="w"></span>
<span class="k">trait</span><span class="w"> </span><span class="n">Treat</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">fn</span> <span class="nf">b</span><span class="p">();</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">user</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Magic</span>::<span class="n">b</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">definer</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">struct</span> <span class="nc">Loc</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">impl</span><span class="w"> </span><span class="n">Treat</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Magic</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">fn</span> <span class="nf">b</span><span class="p">(){</span><span class="w"></span>
<span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">loc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Loc</span><span class="w"> </span><span class="p">{};</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Is there some legitimate use case for this? The fact that you can implement a trait inside a function is certainly weird and confusing but this seems like it could be useful.</p>



<a name="221286077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221286077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221286077">(Dec 31 2020 at 12:06)</a>:</h4>
<p>Yeah I've also written code that does this (define a type in a fn body and implement a trait for it). It is extremely useful, I'd be very sad to see this feature go.</p>



<a name="221286150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221286150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221286150">(Dec 31 2020 at 12:08)</a>:</h4>
<p>IIRC, all that RA needs is that "what happens inside a fn body stays inside a fn body" -- so, impl's for local types are fine, but impl's for outer types are not. I think this is a very reasonable proposal. It would also apply to <code>mod</code> -- <code>mod</code> inside <code>fn</code> is fine <em>if</em> it only affects name resolution inside that <code>fn</code>.<br>
This would permit rustdoc and RA to ignore fn bodies (except for the fn the cursor is currently in, for RA).<br>
This would however invalidate <span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span>'s approach of doing <code>impl Drop</code> inside the constructor.</p>



<a name="221311507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/221311507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#221311507">(Dec 31 2020 at 19:36)</a>:</h4>
<p>Chock another one up for "I define a function local type and give it a drop impl inside that function".</p>
<p>I've even declared extern functions inside of rust functions in <code>stdarch</code>, because only that one rust function ever calls the extern.</p>



<a name="223136418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/223136418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#223136418">(Jan 18 2021 at 15:49)</a>:</h4>
<p>yes, I think the only thing that needs to be forbidden is using local trait or inherent impls outside of that block. Writing a local impl and only using it in that block should be possible to handle in RA</p>



<a name="223145803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/223145803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#223145803">(Jan 18 2021 at 17:16)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="223147003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/forbid%20item%20definitions%20inside%20function%20bodies/near/223147003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/forbid.20item.20definitions.20inside.20function.20bodies.html#223147003">(Jan 18 2021 at 17:28)</a>:</h4>
<p>Since it hasn't been mentioned in this thread yet, cc <a href="https://github.com/rust-lang/rust/issues/65516">https://github.com/rust-lang/rust/issues/65516</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>